<?php
/**
 * Html code of offer editing page (the one with forms).
 * 
 * @package templates
 */

	$cm = CodeManager::getCodeManager();

	if (!Policy::isAdminView())  {
		Error::getError()->addErrorMessage($cm->get("10005"));
		return;
	}
?>

<div id="offer-edit">
<?php
	$formActionString = "/index.php?";
	$formActionString .= Constants::REQ_ACTION."=".Constants::REQ_ACTION_REDIRECT;
	$formActionString .= "&amp;";
	$formActionString .= Constants::REQ_TYPE."=".Constants::REQ_TYPE_SETTINGS;
	
	
	
	$dbConnector = SiteContext::getSiteContext()->getDBConnector();
	
	$isedit = false;
	
	if(isset($_GET[Constants::REQ_ACTION]) && $_GET[Constants::REQ_ACTION] == Constants::REQ_ACTION_SETTINGS) {
		$arr = (array)Settings::getSettings();
		
		foreach (Settings::$CODES_COLUMNS as $columnWithCode) {
			try {
				$res = $dbConnector->query("select * from codeslong where id = ".$arr[$columnWithCode]." limit 1"); // TODO do it without redundancy
				$code = mysql_fetch_assoc($res);
				foreach (SiteLang::$LANG_AVAILABLE as $lang => $unused) {
					$arr[Constants::DB_COMMON_CODESPREFIXFROMAFORM.$lang."_".$columnWithCode] = $code[$lang];
				}
			} catch (ExceptionQueryFailed $e) {
				// code is not available
			}
		}
		
		$isedit = true;
		HtmlHelper::setValuesToInit($arr);
	} else {
		HtmlHelper::setValuesToInit($_POST);
		$id = (int)@$_POST['id'];
	}

?>
	<form action="<?php echo $formActionString; ?>" method="post" enctype="multipart/form-data">
		<table>
			<tr>
				<td class="left"><?php echo $cm->get("30095"); ?>: </td>
				<td class="right">
					<input type="text" onblur="Common.makeFloat(this)" <?php echo HtmlHelper::inputValueWithAttr("eurInCzk"); ?>/>
				</td>
			</tr>
			
			<tr><td colspan="2" class="caption"><?php echo $cm->get("30094"); ?>:</td></tr>
			<tr>
				<td class="left"><?php echo $cm->get("30091"); ?>: </td>
				<td class="right">
					<textarea name="<?php echo Constants::DB_COMMON_CODESPREFIXFROMAFORM."en_mainPage"; ?>"><?php echo HtmlHelper::attributeValue(Constants::DB_COMMON_CODESPREFIXFROMAFORM."en_mainPage"); ?></textarea>
				</td>
			</tr>
			<tr>
				<td class="left"><?php echo $cm->get("30092"); ?>: </td>
				<td class="right">
					<textarea name="<?php echo Constants::DB_COMMON_CODESPREFIXFROMAFORM."cs_mainPage"; ?>"><?php echo HtmlHelper::attributeValue(Constants::DB_COMMON_CODESPREFIXFROMAFORM."cs_mainPage"); ?></textarea>
				</td>
			</tr>
			<tr>
				<td class="left"><?php echo $cm->get("30093"); ?>: </td>
				<td class="right">
					<textarea name="<?php echo Constants::DB_COMMON_CODESPREFIXFROMAFORM."de_mainPage"; ?>"><?php echo HtmlHelper::attributeValue(Constants::DB_COMMON_CODESPREFIXFROMAFORM."de_mainPage"); ?></textarea>
				</td>
			</tr>
			
			<tr><td colspan="2" class="caption"><?php echo $cm->get("30089"); ?>:</td></tr>
			<tr>
				<td class="left"><?php echo $cm->get("30091"); ?>: </td>
				<td class="right">
					<textarea name="<?php echo Constants::DB_COMMON_CODESPREFIXFROMAFORM."en_contactPage"; ?>"><?php echo HtmlHelper::attributeValue(Constants::DB_COMMON_CODESPREFIXFROMAFORM."en_contactPage"); ?></textarea>
				</td>
			</tr>
			<tr>
				<td class="left"><?php echo $cm->get("30092"); ?>: </td>
				<td class="right">
					<textarea name="<?php echo Constants::DB_COMMON_CODESPREFIXFROMAFORM."cs_contactPage"; ?>"><?php echo HtmlHelper::attributeValue(Constants::DB_COMMON_CODESPREFIXFROMAFORM."cs_contactPage"); ?></textarea>
				</td>
			</tr>
			<tr>
				<td class="left"><?php echo $cm->get("30093"); ?>: </td>
				<td class="right">
					<textarea name="<?php echo Constants::DB_COMMON_CODESPREFIXFROMAFORM."de_contactPage"; ?>"><?php echo HtmlHelper::attributeValue(Constants::DB_COMMON_CODESPREFIXFROMAFORM."de_contactPage"); ?></textarea>
				</td>
			</tr>
			
			<tr><td colspan="2" class="caption"><?php echo $cm->get("30101"); ?>:</td></tr>
			<tr>
				<td class="left"><?php echo $cm->get("30091"); ?>: </td>
				<td class="right">
					<textarea name="<?php echo Constants::DB_COMMON_CODESPREFIXFROMAFORM."en_aboutPage"; ?>"><?php echo HtmlHelper::attributeValue(Constants::DB_COMMON_CODESPREFIXFROMAFORM."en_aboutPage"); ?></textarea>
				</td>
			</tr>
			<tr>
				<td class="left"><?php echo $cm->get("30092"); ?>: </td>
				<td class="right">
					<textarea name="<?php echo Constants::DB_COMMON_CODESPREFIXFROMAFORM."cs_aboutPage"; ?>"><?php echo HtmlHelper::attributeValue(Constants::DB_COMMON_CODESPREFIXFROMAFORM."cs_aboutPage"); ?></textarea>
				</td>
			</tr>
			<tr>
				<td class="left"><?php echo $cm->get("30093"); ?>: </td>
				<td class="right">
					<textarea name="<?php echo Constants::DB_COMMON_CODESPREFIXFROMAFORM."de_aboutPage"; ?>"><?php echo HtmlHelper::attributeValue(Constants::DB_COMMON_CODESPREFIXFROMAFORM."de_aboutPage"); ?></textarea>
				</td>
			</tr>
			
			<tr>
				<td colspan="2" class="submit">
<?php 
	$info = SiteContext::getSiteContext();
	$random = Common::createFormHash();
	$info->setFormHash($random);
?>
					<input type="text" class="invisible" <?php echo HtmlHelper::inputValueWithAttr("id"); ?>/>
					<input type="text" value="<?php echo $random; ?>" class="invisible" name="formHash" />
					<input class="submit middle" type="submit" value="<?php echo $cm->get("20005"); ?>" />
					<input class="clear middle" type="button" onclick="Common.clearForm(this.form)" value="<?php echo $cm->get("20007"); ?>" />
				</td>
			</tr>
		</table>
	</form>